<?php

namespace App\Controllers;

use Xxh\Bos\BosStorage;

class CollectController extends  Controller
{

    protected $url;

    public function __construct()
    {


    }


    public function downImg()
    {




    }



    protected $savePath = '';
    public function getImgs($param)
    {


        $url = $param[0];

        $content = resolve('request')->send($url);

        $imgs = resolve('match')->findImg($content);

        $this->savePath = storage_path().collectPathName($url);
        $this->mkdir();

        foreach ($imgs as $i=>$img){
            if( $img == '')
                continue;
            //@$content = file_get_contents($this->imgUrl($img));
            //   $content = 'data://image/jpeg;base64,'. base64_encode($content);
            //     dd(getimagesize($content));
     //      file_put_contents($this->savePath.'/'.$i.'.png',$content);
        }

          resolve('zip')->zipFolder($this->savePath);
    }


    public function mkdir()
    {

        if(! is_dir($this->savePath)) {
            mkdir($this->savePath);
        }
    }


    public function imgUrl($url)
    {


        if( strpos($url,"http") === 0)
        return $url;
        return 'http:'.$url;
    }






}
